/**
 *Created by Heqi on 2018/1/20.
 */

import http from '@/utils/http'
import moment from 'moment'

const URL = '/rest/customer/report/adjust-reports'

export default {
  list ({search}, cb) {
    const start = undefined === search.date || search.date.length <= 0 ? defaultDate()[0] : search.date[0]
    const end = undefined === search.date || search.date.length <= 0 ? defaultDate()[1] : search.date[1]
    http.get(URL, {
      params: {
        startTime: start,
        endTime: end,
        platformId: search.platformId,
        itemTitle: search.itemTitle,
        page: search.page,
        pageSize: search.pageSize
      }
    }).then(response => cb(response)).catch(trace => cb(trace.response))
  }
}

const defaultDate = function () {
  let start = moment().format('YYYY-MM-01')
  let end = moment().format('YYYY-MM-DD')
  return [start, end]
}
